import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';
import Router from "vue-router"
import router from './router/index'
import store from './store/index'
import axios from 'axios'
import echarts from 'echarts'


import VueParticles from 'vue-particles'
import moment from 'moment'
Vue.prototype.$moment = moment
Vue.use(VueParticles)
Vue.config.productionTip = false
axios.defaults.baseURL='http://localhost:8888';
Vue.prototype.$axios = axios;
Vue.prototype.$echarts = echarts

Vue.use(ElementUI);

Vue.use(Router);

const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}
// 添加请求拦截器，在请求头中加token
axios.interceptors.request.use(
  config => {
    if (localStorage.getItem('Authorization')) {
      config.headers.Authorization = localStorage.getItem('Authorization');
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  });

axios.interceptors.response.use(
  response => {
    // console.log(response)
    let res = response.data.code;
    if (res == "50000") {
      alert("token超时，请重新登录");
      localStorage.clear();
      router.push({
        name: 'login'
      })
    }
    return response;
  }
);
new Vue({
  render: h => h(App),
  router,
  store,
  axios
}).$mount('#app')


